//公共参数
var version = '0';
var visit_plat = '0';
var visit_type = '0';
var is_used = "0";

var publicParam={
    version:version,
    visit_plat:visit_plat,
    visit_type:visit_type,
    is_used:is_used
}

// var path="http://192.168.1.180:8083"//张
//var path="http://192.168.1.107:8083"//黄
// var path="http://192.168.1.102:8083"//赵
//var path="http://192.168.1.195:8083"//陈
var path="http://203.195.170.84:8083"//线上
/*var path="http://192.168.1.177:8083" */
// var path="http://192.168.1.102:8083"
// var path="http://192.168.43.178:8083"
// var path="http://localhost:8083"

//级联默认显示样式
$(function () {	
    var unSelected = "#999";
    var selected = "#333";
    $(function () {
        $(".select-jilian").css("color", unSelected);
        $("option").css("color", selected);
        $("select").change(function () {
            var selItem = $(this).val();
            if (selItem == $(this).find('option:first').val()) {
                $(this).css("color", unSelected);
            } else {
                $(this).css("color", selected);
            }
        });
    })
})

//获取所有实操课编号
function getOperation() {
    //			时间戳
    var stamp = new Date().getTime();
    //			存储的token
    var systoken=sessionStorage.getItem('systoken');
    var param = {
        stamp: stamp,
        version: 0,
        visit_plat: 0,
        visit_type: 0,
        is_used: 0
    };
    var $code = $("#codes");
    param = JSON.stringify(param);
    var url = path+"/student/getAllStudents";
    $.ajax({
        url: url,
        data: {param: param},
        dataType: 'json',
        type: 'post',
        headers: {Authorization: systoken},
        success: function (res) {
            var rows = res.rows;
            var length = rows.length;
            var h
            for (var i = 0; i < length; i++) {
                h +="<option value ='"+rows[i].id+"'>" + rows[i].name + "</option>";
            }
            //$code.val(h)
            $('#codes').append(h)
            layui.use('form', function(){
//              layui.form.read()
            });
        }
    })
}

//获取所有班级ID
function queryClasses() {
    //			时间戳
    var stamp = new Date().getTime();
    //			存储的token
    var systoken = sessionStorage.getItem("systoken");
    var className = "";
    var startTime = "";
    var endTime = "";
    var updateTime = "";
    var param = {
        stamp: stamp,
        systoken: systoken,
        className: className,
        startTime: startTime,
        endTime: endTime,
        updateTime: updateTime,
        version: 0,
        visit_plat: 0,
        visit_type: 0,
        is_used: 0,
    };
    param = JSON.stringify(param);
    var $classId = $(".classId");
    var url = path+"/classes/queryClasses";
    $.ajax({
        url: url,
        data: {param: param},
        dataType: 'json',
        type: 'post',
        async: false,
        headers: {Authorization: systoken},
        success: function(res) {
            var rows = res.rows;
            var length = rows.length;
            for(var i = 0; i < length; i++) {
                var $banjiopt = $("<option " + "value=" + rows[i].id + ">" + rows[i].id + "</option>");
                $classId.append($banjiopt)
            }
        }
    })
}

var IDreg = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
var phoneReg = /^[1][3,4,5,7,8,6,9][0-9]{9}$/;
var passReg = /^[\S]{6,12}$/;
var accountReg = /^[\S]{3,12}$/;
var emailReg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //邮箱
var heightReg = /^[1-9]\d*$/; //身高

//验证身份证
function checkIdCard(value) { 
	if(value == null || !IDreg.test(value)) {
		alert("请填写正确的身份证号码!");
		return false;
	}
	return true;
};
//验证联系方式
function checkLiaison(value) {
	if(value == null || !phoneReg.test(value)) {
		alert("请填写正确的手机号码!");
		return false;
	}
	return true;
}
 //			验证账号
function checkAccount(value) {
	if(!accountReg.test(value)) {
		alert("账号必须为3位以上!");
		return false;
	}
	if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
		alert('账号不能有特殊字符');
		return false;
	}
	if(/(^\_)|(\__)|(\_+$)/.test(value)) {
		alert('账号首尾不能出现下划线\'_\'');
		return false
	}
	if(/^\d+\d+\d$/.test(value)) {
		alert('账号不能全为数字');
		return false;
	}
	return true;
}
//验证密码
function checkPssWord(value) { 
	if(value == null || !passReg.test(value)) {
		alert("密码必须6到12位，且不能出现空格!");
		return false;
	}
	return true;
}
 //验证确认密码
function checkConfrimPssWord(Firstvalue,confirmValue) {
	if(confirmValue == null || !passReg.test(confirmValue)) {
		alert("密码必须6到12位，且不能出现空格!");
		return false;
	}
	if(Firstvalue != confirmValue) {
		alert("两次输入的密码不一致!")
		return false;
	}
	return true;
}

//验证邮箱
function checkEmail(value) {
	if(!emailReg.test(value)) {
		alert("请填写正确格式的邮箱!");
		return false;
	}
	return true;
}

//验证身高
function checkHeight(value,tips) {
	if(value == null || !heightReg.test(value)) {
		alert(tips);
		return false;
	}
	return true;
}

//关闭弹框,新增公共关闭弹框函数,使用的前提是有layer环境
function closeIframe() {
	parent.layer.closeAll();
}

//请求成功和共用弹框
function setTips(value){
	layui.use(['layer'],function(){
		var that=this;
		var layer=layui.layer;
		layer.msg(value);
	})
}